<?php
			ob_start();			
?>
<?php
		
		if (isset($_COOKIE["user"])) {
			// if cookie <> ""
		  }
		  else
		  {
			  header("location:login.php");
			  
		  }
?>
<!-- begin ckeidtor -->
<script type="text/javascript" src="tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({			 
	theme : "advanced",
	mode : "textareas",
    plugins : "autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
	// Theme options
	theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect",
	theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,code,forecolor,backcolor",
	theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,fullscreen,insertfile,insertimage",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_statusbar_location : "bottom",
	theme_advanced_resizing : true,
	theme_advanced_font_sizes : "10px,12px,14px,16px,24px",
});
</script>
<!-- end cheditor-->
<?php
                    if(isset($_POST["btnsubmit"]))
                    {
						$uploadfile = escapeValue($_FILES["uploadfile"]["name"]);
						$title=escapeValue($_POST["txttitle"]);
						$message=escapeValue($_POST["txtmessage"]);
						$published=escapeValue($_POST["cbopublished"]);

							if(@$errors == "")
								{
									if($uploadfile=="")
									{
											$sql = "INSERT INTO tbl_activity(act_title, message
											,published, date_post) 
											VALUES('$title','$message','$published',now())";
											if(query($sql))
											{
												errorMessage("Inséré avec succès ...!");
												//clear data
												$uploadfile ="";
												$title="";
												$message="";
												$published="";
											}
									}
									elseif($published=="")
									{
										errorMessage("S'il vous plaît sélectionner publier ...!");	
									}
									else
									{
										
										if(@$errors == "")
										{
											// Block rezier image
											$photo = validImage("uploadfile",5000, 5000);		
												//validImage($file,$imgX, $imgY);
												if ($photo === true){
													
											//Upload Image
												$photoid = mysql_insert_id();
												$image_name = $_FILES["uploadfile"]["name"];
												$image_tmp_name = $_FILES["uploadfile"]["tmp_name"];
												$ext = "jpg";	
												$tag = "";
												$path = "actuality/";
												//$filename = "$photoid.$ext";
												$filename=$image_name;		
												$width = 220;
												$height = 160;
												
												createImageAndThumb($image_tmp_name,$filename,
																	$width,
																	$height,
																	$tag,
																	$path,
																	$image_name);
										//end upload image							
												}
										//end block rezier image
											
											$sql = "INSERT INTO tbl_activity(act_title, message
											,published, date_post, photo) 
											VALUES('$title','$message','$published',now(),'$uploadfile')";
											if(!query($sql))
											{
												deleteFile("activity/".$uploadfile);
											}
											else
											{
												errorMessage("Inséré avec succès ...!");
												//clear data
												$uploadfile ="";
												$title="";
												$message="";
												$published="";

											}
										}
									}			
													
								}//end check error=""
							
							
                    } //end isset btnsubmit
                ?>

                	<div id="border_cont_title">
                        	<div id='content_title_left'>Insérez actaulity</div>
                            <div id='content_title_right'></div>
					</div> <!--end border_cont_title-->
                    <?php echo @$errors;?>
                   
                    	 <!--start table -->
                    <form action="index.php?page=actualityNew" method="post" enctype="multipart/form-data">
                    	<table width="765px" align="left">
                        	<tr>
                            	
                            	<td align="left" height="30" bgcolor="#FFEAD7">Envoyer la photo*</td>
                                <td>
                                	<input class="submit" type="file" name="uploadfile" />
                                </td>
                                
                            </tr>
                            <tr>
                            	<td align="left" height="30" bgcolor="#FFEAD7">Titre</td>
                                <td>
                                <input type="text" name="txttitle" value=""  size="38" />
                                </td>
                            </tr>
                            <tr>
                            	<td align="left" height="30" bgcolor="#FFEAD7">Description</td>
                                <td colspan="2" >
                                
                                   <textarea name="txtmessage"  cols="40" rows="10" id="txtmessage"  wrap="virtual"></textarea>				                              
                                </td>
                            </tr>
                            <tr>
                            	<td align="left" height="30" bgcolor="#FFEAD7">Publier</td>
                                <td align="left" height="30">
                                	<select name="cbopublished" >
                                    <option value=""> -- Sélectionnez Publier -- </option>
                                       
									<?php
										$sql = "SELECT * FROM tbl_zeroone";
                                    $result = query($sql);
                                    while($row = fetch_assoc($result))
                                    {
                                        
                                        if(@$showFront == $row['zeroone_value'])
                                            $selected = " selected='selected'";
											
                                        else	
                                            $selected = "";
                                	?>
                                        <option value="<?php echo $row['zeroone_value'];?>"<?php echo $selected;?>>
                                        <?php echo $row['zeroone_name'];?></option>
                                        
                                	<?php
										
                                    }
                                   
                                  	?>
                                        
                                    </select>
                                </td>
                            </tr>
                            <tr>
                            	<td align="left" height="30" bgcolor="#FFEAD7">Action</td>
                                <td align="left" height="30">
                                <input class="submit" type="submit" name="btnsubmit" value="Soumettre"  />
                                <input class="submit" type="button" name="btncancel" value="Annuler" onclick="redirect('index.php?page=actuality')" />
                                </td>
                            </tr>
                            
                        </table>
                        </form>
                    <!--end table -->
                   